package org.wlldTest.svd;

import org.dromara.easyai.matrixTools.Matrix;
import org.dromara.easyai.matrixTools.MatrixOperation;
import org.dromara.easyai.matrixTools.SVDBody;

public class Svd {


    public static void main(String[] args) throws Exception {
        test();
    }

    public static void test() throws Exception {//月，日 时
        MatrixOperation matrixOperation = new MatrixOperation();
        Matrix matrix = new Matrix(4, 3, "[3,3,1]#[2,3,4]#[1,1,2]#[5,5,3]#");
        System.out.println("输出原矩阵========");
        System.out.println(matrix);
        System.out.println("做SVD分解，分解迭代进行300次迭代========当矩阵设置合适的大小，该行为是个必定耗时的行为");
        SVDBody svdBody = matrixOperation.svd(matrix, 300, 3);
        System.out.println("分解结果========");
        System.out.println(svdBody.getMatrixU());
        System.out.println(svdBody.getFeature());
        System.out.println(svdBody.getMatrixVT());
        System.out.println("将三个分解后的矩阵相乘，验证于原矩阵差距:");
        Matrix a = matrixOperation.mulMatrix(matrixOperation.mulMatrix(svdBody.getMatrixU(), svdBody.getFeature()), svdBody.getMatrixVT());
        System.out.println(a);

    }
}
